# coding=utf-8
# @Author:zcx
# @Time:2024/9/12 17:03
import sys
from PySide6.QtGui import QAction
from PySide6.QtWidgets import QApplication, QWidget, QMenuBar, QMenu

class MyMainWindow(QWidget):
    def __init__(self):
        super().__init__()
        self.resize(600, 400)
        self.setWindowTitle("菜单栏")
        menu_bar = QMenuBar(self)

        file_menu = QMenu("文件", self)
        edit_menu = QMenu("编辑", self)
        see_menu = QMenu("查看", self)

        # 给菜单添加动作
        new_act = QAction("新建文件", self)
        openact = QAction("打开文件", self)
        saveact = QAction("保存文件", self)
        file_menu.addActions([new_act, openact, saveact])

        # 编辑的操作
        copyact = QAction("复制", self)
        cutact = QAction("剪切", self)
        pasteact = QAction("粘贴", self)
        edit_menu.addActions([copyact, cutact, pasteact])

        # 查看的子菜单栏
        sub_menu = QMenu("外观", self)
        appear = QAction("全屏", self)
        center = QAction("居中", self)
        left = QAction("居左", self)
        right = QAction("居右", self)
        sub_menu.addActions([appear, center, left, right])
        # 把外观的菜单栏放入查看的菜单栏下
        see_menu.addMenu(sub_menu)

        menu_bar.addMenu(file_menu)
        menu_bar.addMenu(edit_menu)
        # 把查看的菜单栏放入到menbar下
        menu_bar.addMenu(see_menu)



if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = MyMainWindow()
    window.show()
    sys.exit(app.exec())